﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="edit.aspx.cs" Inherits="StoreWeb.system.role.edit" %>

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
<script type="text/javascript" src="../../lib/html5.js"></script>
<script type="text/javascript" src="../../lib/respond.min.js"></script>
<script type="text/javascript" src="../../lib/PIE_IE678.js"></script>
<![endif]-->
    <link href="../../css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="../../css/H-ui.admin.css" rel="stylesheet" type="text/css" />
    <link href="../../css/style.css" rel="stylesheet" type="text/css" />
    <link href="../../lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="../../lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="../../lib/layer/1.9.3/layer.js"></script>
    <script type="text/javascript" src="../../lib/Validform/5.3.2/Validform.min.js"></script>
    <script type="text/javascript" src="../../lib/laypage/1.2/laypage.js"></script>
    <script type="text/javascript" src="../../lib/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="../../js/H-ui.js"></script>
    <script type="text/javascript" src="../../js/H-ui.admin.js"></script>
    <script type="text/javascript" src="../../lib/icheck/jquery.icheck.min.js"></script>
    <!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
    <title>新建角色</title>
</head>
<body>
    <div class="pd-20">
        <form runat="server" method="post" class="form form-horizontal" id="formmemberadd">
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色编号：</label>
                <div class="formControls col-xs-8 col-sm-9" style="width:300px;">
                    <input type="text" class="input-text" value="" placeholder="" id="code" name="code" runat="server" datatype="*4-16" nullmsg="角色编号不能为空">
                </div>
                <div class="col-4"></div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
                <div class="formControls col-xs-8 col-sm-9" style="width:300px;">
                    <input type="text" class="input-text" value="" placeholder="" id="username" name="username" runat="server" datatype="*1-200" nullmsg="角色名称不能为空">
                </div>
                <div class="col-4"></div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">备注：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="" placeholder="" id="note" name="note" runat="server">
                </div>
            </div>

            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3">系统角色：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <asp:Repeater ID="rptone" runat="server" OnItemDataBound="rptone_ItemDataBound">
                        <ItemTemplate>
                            <dl class="permission-list">
                                <dt>
                                    <label>
                                        <input type="checkbox" <%#getrrlist(code.Value,Eval("code").ToString(),Eval("code").ToString()) %>  name='<%#Eval("code") %>' id='<%#Eval("code") %>'>
                                        <%#Eval("rightname") %></label>
                                </dt>
                                <dd>
                                    <asp:HiddenField ID="hidparentcode" runat="server" Value='<%#Eval("code") %>' />
                                    <asp:Repeater ID="rpttrue" runat="server">
                                        <ItemTemplate>
                                            <dl class="cl permission-list2">
                                                <dt>
                                                    <label class="">
                                                        <input type="checkbox" value=""  <%#get(code.Value,Eval("code").ToString()) %>  name="extension" id="<%#Eval("code") %>">
                                                        <%#Eval("rightname") %></label>
                                                </dt>
                                                <dd>
                                                    <%#extension(Eval("code").ToString(),Eval("extension").ToString()) %>
                                                </dd>
                                            </dl>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                </dd>
                            </dl>
                        </ItemTemplate>
                    </asp:Repeater>
                </div>
            </div>
            <div class="row cl">
                <div class="col-10 col-offset-2">
                    <asp:HiddenField ID="hidid" runat="server" />
                    <asp:Button ID="btnok" runat="server" CssClass="btn btn-success radius" Text="确定" OnClick="btnok_Click" />
                </div>
            </div>
        </form>
    </div>
    <script>
        $(function () {
            $(function () {
                $(".permission-list dt input:checkbox").click(function () {
                    $(this).closest("dl").find("dd input:checkbox").prop("checked", $(this).prop("checked"));
                });
                $(".permission-list2 dd input:checkbox").click(function () {
                    var l = $(this).parent().parent().find("input:checked").length;
                    var l2 = $(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
                    if ($(this).prop("checked")) {
                        $(this).closest("dl").find("dt input:checkbox").prop("checked", true);
                        $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked", true);
                    }
                    else {
                        if (l == 0) {
                            $(this).closest("dl").find("dt input:checkbox").prop("checked", false);
                        }
                        if (l2 == 0) {
                            $(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked", false);
                        }
                    }
                });
                $("#formmemberadd").Validform({
                    tiptype: 2,
                    btnSubmit: "#btnok",
                    beforeSubmit: function (curform) {
                        var valuelist = ""; //保存checkbox选中值
                        //遍历name以listTest开头的checkbox
                        $("input[type=checkbox]:checked").each(function () {
                            if (this.checked && $(this).attr("name") != "extension") {
                                //$(this):当前checkbox对象;
                                //$(this).parent("span"):checkbox父级span对象
                                if (valuelist == "") {
                                    valuelist = $(this).attr("name") + "," + $(this).attr("id");
                                } else {
                                    valuelist += "|" + $(this).attr("name") + "," + $(this).attr("id");
                                }
                            }
                        });
                        $.post("../../ajax/role.aspx", { code: $("#code").val(), username: $("#username").val(), note: $("#note").val(), id: $("#hidid").val(), extensionlist: valuelist },
                            function (data) {
                                if (data == 1) {
                                    parent.layer.alert("添加成功", function () {
                                        parent.location.reload();
                                    });
                                } else if (data == 2) {
                                    parent.layer.alert("修改成功", function () {
                                        parent.location.reload();
                                    });
                                } else {
                                    parent.layer.msg("操作失败");
                                }
                            });
                        return false;
                    }
                });
            });
        });
    </script>
</body>
</html>

